<template>
  <div class="labels-view">
    <div class="page-header">
      <h1>标签云</h1>
      <p>发现感兴趣的内容标签</p>
    </div>

    <div class="labels-container" v-loading="loading">
      <div v-if="labels.length === 0" class="empty-state">
        <el-empty description="暂无标签数据" />
      </div>
      
      <div v-else class="labels-grid">
        <div 
          v-for="label in labels" 
          :key="label.labelId"
          class="label-item"
          @click="goToLabelNotes(label.labelId)"
        >
          <NoteLabelComponent :label="label" />
        </div>
      </div>
    </div>
  </div>
</template>

<script setup lang="ts">
import { ref, onMounted } from 'vue'
import { useRouter } from 'vue-router'
import { getNoteLabels } from '@/api/note'
import type { NoteLabel } from '@/types/api'
import NoteLabelComponent from '@/components/NoteLabel.vue'

const router = useRouter()
const loading = ref(false)
const labels = ref<NoteLabel[]>([])

onMounted(() => {
  loadLabels()
})

const loadLabels = async () => {
  loading.value = true
  try {
    const response = await getNoteLabels()
    if (response.code === 200) {
      labels.value = response.data
    }
  } catch (error) {
    console.error('获取标签失败:', error)
  } finally {
    loading.value = false
  }
}

const goToLabelNotes = (labelId: number) => {
  router.push(`/label/${labelId}`)
}
</script>

<style scoped>
.labels-view {
  max-width: 1200px;
  margin: 0 auto;
  padding: 20px;
}

.page-header {
  text-align: center;
  margin-bottom: 30px;
}

.page-header h1 {
  font-size: 2rem;
  color: #303133;
  margin-bottom: 10px;
}

.page-header p {
  color: #909399;
  font-size: 1rem;
}

.labels-container {
  min-height: 400px;
}

.labels-grid {
  display: flex;
  flex-wrap: wrap;
  gap: 12px;
  justify-content: center;
}

.label-item {
  cursor: pointer;
  transition: transform 0.2s ease;
}

.label-item:hover {
  transform: scale(1.1);
}

@media (max-width: 768px) {
  .labels-view {
    padding: 15px;
  }
  
  .page-header h1 {
    font-size: 1.5rem;
  }
}
</style>